package ControlLayer;
import ModelLayer.*;
import DBLayer.*;

import java.util.ArrayList;

public class SupplierCtr 
{
	 public SupplierCtr(){}
	 
	 public ArrayList<Supplier> getAllSuppliers()
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 ArrayList<Supplier> allSup=new ArrayList<Supplier>();
		 allSup=dbSupp.getAllSupp(false);
		 return allSup;
	 }
	 
	 public Supplier getSuppById(int id)
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 return dbSupp.getSuppById(id, false);
	 }
	 
	 public Supplier getSupplierByName(String name)
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 return dbSupp.getSupplierByName(name, false);
	 }
	 
	 public void inserNewSupplier(/*int SuppID,*/ String Name, String Address, String Country, String PhoneNo, String E_Mail)
	 {
		 Supplier newSupp=new Supplier();
		 newSupp.setAddress(Address);
		 newSupp.setCountry(Country);
		 newSupp.setEmail(E_Mail);
		 //newSupp.setSuppId(SuppID);
		 newSupp.setName(Name);
		 newSupp.setPhoneNo(PhoneNo);
		 
		 try
		 {
			 DBConnection1.startTransaction();
			 DBSupplier dbSupp=new DBSupplier();
			 dbSupp.insertSupplier(newSupp);
			 DBConnection1.commitTransaction();
		 }
		 catch(Exception e)
		 {
			 DBConnection1.rollbackTransaction();
		 }
	 }
	 
	 public int updateSupplierByID(int SuppID, String Name, String Address, String Country, String PhoneNo, String E_Mail)
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 
		 Supplier newSupp=new Supplier();
		 newSupp.setAddress(Address);
		 newSupp.setCountry(Country);
		 newSupp.setEmail(E_Mail);
		 newSupp.setId(SuppID);
		 newSupp.setName(Name);
		 newSupp.setPhoneNo(PhoneNo);
		 
		 return dbSupp.updateSupplierByID(newSupp);		 
	 }
	 
	 public int updateSupplierByName(String Name, String Address, String Country, String PhoneNo, String E_Mail)
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 
		 Supplier newSupp=new Supplier();
		 newSupp.setAddress(Address);
		 newSupp.setCountry(Country);
		 newSupp.setEmail(E_Mail);		 
		 newSupp.setName(Name);
		 newSupp.setPhoneNo(PhoneNo);
		 
		 return dbSupp.updateSupplierByID(newSupp);	
	 }
	 
	 public int deleteSupplierByID(int id)
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 return dbSupp.deleteSupplierByID(id);		
	 }
	 
	 public int deleteSupplierByName(String name)
	 {
		 IFDBSupplier dbSupp=new DBSupplier();
		 return dbSupp.deleteSupplierByName(name);
	 }
}